home *** CD-ROM | disk | FTP | other *** search
/ Software of the Month Club 2000 October / Software of the Month - Ultimate Collection Shareware 277.iso / pc / PROGRAMS / UTILITY / WINLINUX / DATA1.CAB / programs_-_include / LINUX / HFMODEM.H < prev    next >
C/C++ Source or Header  |  1999-09-17  |  8KB  |  257 lines

  1. /*****************************************************************************/
  2.  
  3. /*
  4.  *      hfmodem.h  --  Linux soundcard HF FSK driver.
  5.  *
  6.  *      Copyright (C) 1997  Thomas Sailer (sailer@ife.ee.ethz.ch)
  7.  *        Swiss Federal Institute of Technology (ETH), Electronics Lab
  8.  *
  9.  *      This program is free software; you can redistribute it and/or modify
  10.  *      it under the terms of the GNU General Public License as published by
  11.  *      the Free Software Foundation; either version 2 of the License, or
  12.  *      (at your option) any later version.
  13.  *
  14.  *      This program is distributed in the hope that it will be useful,
  15.  *      but WITHOUT ANY WARRANTY; without even the implied warranty of
  16.  *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17.  *      GNU General Public License for more details.
  18.  *
  19.  *      You should have received a copy of the GNU General Public License
  20.  *      along with this program; if not, write to the Free Software
  21.  *      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  22.  *
  23.  *
  24.  *  This is the Linux realtime sound output driver
  25.  */
  26.  
  27. /*****************************************************************************/
  28.  
  29. #ifndef _HFMODEM_H
  30. #define _HFMODEM_H
  31. /* --------------------------------------------------------------------- */
  32.  
  33. #include <linux/version.h>
  34.  
  35. #include <linux/ioctl.h>
  36. #include <linux/types.h>
  37. #include <linux/fs.h>
  38. #if LINUX_VERSION_CODE >= 0x20100
  39. #include <linux/poll.h>
  40. #endif
  41.  
  42. /* --------------------------------------------------------------------- */
  43.  
  44. #define HFMODEM_MINOR         145
  45.  
  46. #define HFMODEM_SRATE        8000
  47. #define HFMODEM_MAXBITS      4800   /* required for GTOR 300 baud mode */
  48. #define HFMODEM_MINBAUD        40
  49. #define HFMODEM_MAXBAUD       400
  50. #define HFMODEM_MAXCORRLEN   ((HFMODEM_SRATE+HFMODEM_MINBAUD-1)/HFMODEM_MINBAUD)
  51.  
  52. /* --------------------------------------------------------------------- */
  53.  
  54. typedef unsigned long hfmodem_time_t;
  55. typedef int hfmodem_soft_t;
  56. typedef unsigned long hfmodem_id_t;
  57.  
  58. /* --------------------------------------------------------------------- */
  59.  
  60. struct hfmodem_ioctl_fsk_tx_request {
  61.     hfmodem_time_t tstart;
  62.     hfmodem_time_t tinc;
  63.     int inv;
  64.     hfmodem_id_t id;
  65.     unsigned int nbits;
  66.     unsigned char *data;
  67.     unsigned int freq[2];
  68. };
  69.  
  70. struct hfmodem_ioctl_fsk_rx_request {
  71.     hfmodem_time_t tstart;
  72.     hfmodem_time_t tinc;
  73.     unsigned int baud;
  74.     hfmodem_id_t id;
  75.     unsigned int nbits;
  76.     hfmodem_soft_t *data;
  77.     unsigned int freq[2];
  78. };
  79.  
  80. struct hfmodem_ioctl_mixer_params {
  81.     int src;
  82.     int igain;
  83.     int ogain;
  84. };
  85.  
  86. struct hfmodem_ioctl_sample_params {
  87.     __s16 *data;
  88.     int len;
  89. };
  90.  
  91. #define HFMODEM_IOCTL_FSKTXREQUEST    _IOW('H', 0, struct hfmodem_ioctl_fsk_tx_request)
  92. #define HFMODEM_IOCTL_FSKRXREQUEST    _IOW('H', 1, struct hfmodem_ioctl_fsk_rx_request)
  93. #define HFMODEM_IOCTL_CLEARRQ         _IO('H',  3)
  94. #define HFMODEM_IOCTL_GETCURTIME      _IOR('H', 4, hfmodem_time_t)
  95. #define HFMODEM_IOCTL_WAITRQ          _IOR('H', 5, hfmodem_id_t)
  96. #define HFMODEM_IOCTL_MIXERPARAMS     _IOW('H', 6, struct hfmodem_ioctl_mixer_params)
  97. #define HFMODEM_IOCTL_SAMPLESTART     _IOW('H', 7, struct hfmodem_ioctl_sample_params)
  98. #define HFMODEM_IOCTL_SAMPLEFINISHED  _IO('H',  8)
  99.  
  100. /* --------------------------------------------------------------------- */
  101. #ifdef __KERNEL__
  102.  
  103. #include <linux/parport.h>
  104.  
  105. #define DMA_MODE_AUTOINIT      0x10
  106.  
  107. #define NR_DEVICE 1
  108.  
  109. #define HFMODEM_FRAGSAMPLES (HFMODEM_SRATE/100)
  110. #define HFMODEM_FRAGSIZE    (HFMODEM_FRAGSAMPLES*2)
  111. #define HFMODEM_NUMFRAGS    8
  112. #define HFMODEM_EXCESSFRAGS 3
  113.  
  114. #define HFMODEM_NUMRXSLOTS 20
  115. #define HFMODEM_NUMTXSLOTS 4
  116.  
  117. #define HFMODEM_CORRELATOR_CACHE 8
  118.  
  119. enum slot_st { ss_unused = 0, ss_ready, ss_oper, ss_retired };
  120. typedef int hfmodem_conv_t;
  121.  
  122. struct hfmodem_state {
  123.     const struct hfmodem_scops *scops;
  124.  
  125.     /* io params */
  126.     struct {
  127.         unsigned int base_addr;
  128.         unsigned int dma;
  129.         unsigned int irq;
  130.     } io;
  131.  
  132.     struct {
  133.         unsigned int seriobase;
  134.         unsigned int pariobase;
  135.         unsigned int midiiobase;
  136.         unsigned int flags;
  137.         struct pardevice *pardev;
  138.     } ptt_out;
  139.  
  140.     struct {
  141.         __s16 *buf;
  142.         unsigned int lastfrag;
  143.         unsigned int fragptr;
  144.         unsigned int last_dmaptr;
  145.         int ptt_frames;
  146.     } dma;
  147.  
  148.     struct {
  149.         unsigned int last_tvusec;
  150.         unsigned long long time_cnt;
  151.         hfmodem_time_t lasttime;
  152. #ifdef __i386__
  153.         unsigned int starttime_lo, starttime_hi;
  154. #endif /* __i386__ */
  155.     } clk;
  156.  
  157.     int active;
  158.     struct wait_queue *wait;
  159.  
  160.     struct {
  161.         __s16 *kbuf;
  162.         __s16 *ubuf;
  163.         __s16 *kptr;
  164.         unsigned int size;
  165.         int rem;
  166.     } sbuf;
  167.  
  168.     struct {
  169.         hfmodem_time_t last_time; 
  170.         unsigned int tx_phase;
  171.         
  172.         struct hfmodem_l1_rxslot {
  173.             enum slot_st state;
  174.             hfmodem_time_t tstart, tinc;
  175.             hfmodem_soft_t *data;
  176.             hfmodem_soft_t *userdata;
  177.             unsigned int nbits;
  178.             unsigned int cntbits;
  179.             hfmodem_id_t id;
  180.             unsigned int corrlen;
  181.             hfmodem_conv_t scale;
  182.             unsigned int corr_cache;
  183.         } rxslots[HFMODEM_NUMRXSLOTS];
  184.         
  185.         struct hfmodem_l1_txslot {
  186.             enum slot_st state;
  187.             hfmodem_time_t tstart, tinc;
  188.             unsigned char *data;
  189.             unsigned int nbits;
  190.             unsigned int cntbits;
  191.             hfmodem_id_t id;
  192.             unsigned char inv;
  193.             unsigned int phinc;
  194.             unsigned int phase_incs[2];
  195.         } txslots[HFMODEM_NUMTXSLOTS];
  196.     } l1;
  197. };
  198.  
  199. struct hfmodem_correlator_cache {
  200.     int refcnt;
  201.     int lru;
  202.     unsigned short phase_incs[2];
  203.     hfmodem_conv_t correlator[2][2][HFMODEM_MAXCORRLEN];
  204. };
  205.  
  206. struct hfmodem_scops {
  207.     unsigned int extent;
  208.  
  209.     void (*init)(struct hfmodem_state *dev);
  210.     void (*prepare_input)(struct hfmodem_state *dev);
  211.     void (*trigger_input)(struct hfmodem_state *dev);
  212.     void (*prepare_output)(struct hfmodem_state *dev);
  213.     void (*trigger_output)(struct hfmodem_state *dev);
  214.     void (*stop)(struct hfmodem_state *dev);
  215.     unsigned int (*intack)(struct hfmodem_state *dev);
  216.     void (*mixer)(struct hfmodem_state *dev, int src, int igain, int ogain);
  217. };
  218.  
  219. /* --------------------------------------------------------------------- */
  220.  
  221. extern int hfmodem_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg);
  222. #if LINUX_VERSION_CODE >= 0x20100
  223. extern unsigned int hfmodem_poll(struct file *file, poll_table *wait);
  224. #else
  225. extern int hfmodem_select(struct inode *inode, struct file *file, int sel_type, select_table *wait);
  226. #endif
  227.  
  228. extern void hfmodem_clear_rq(struct hfmodem_state *dev);
  229. extern void hfmodem_input_samples(struct hfmodem_state *dev, hfmodem_time_t tstart, 
  230.                 hfmodem_time_t tinc, __s16 *samples);
  231. extern int hfmodem_output_samples(struct hfmodem_state *dev, hfmodem_time_t tstart, 
  232.                 hfmodem_time_t tinc, __s16 *samples);
  233. extern long hfmodem_next_tx_event(struct hfmodem_state *dev, hfmodem_time_t curr);
  234. extern void hfmodem_finish_pending_rx_requests(struct hfmodem_state *dev);
  235. extern void hfmodem_wakeup(struct hfmodem_state *dev);
  236.  
  237.  
  238. extern int hfmodem_sbcprobe(struct hfmodem_state *dev);
  239. extern int hfmodem_wssprobe(struct hfmodem_state *dev);
  240.  
  241. extern void hfmodem_refclock_probe(void);
  242. extern void hfmodem_refclock_init(struct hfmodem_state *dev);
  243. extern hfmodem_time_t hfmodem_refclock_current(struct hfmodem_state *dev, hfmodem_time_t expected, int exp_valid);
  244.  
  245. /* --------------------------------------------------------------------- */
  246.  
  247. extern const char hfmodem_drvname[];
  248. extern const char hfmodem_drvinfo[];
  249.  
  250. extern struct hfmodem_state hfmodem_state[NR_DEVICE];
  251. extern struct hfmodem_correlator_cache hfmodem_correlator_cache[HFMODEM_CORRELATOR_CACHE];
  252.  
  253. /* --------------------------------------------------------------------- */
  254. #endif /* __KERNEL__ */
  255. /* --------------------------------------------------------------------- */
  256. #endif /* _HFMODEM_H */
  257.